const http = require('http');
const querystring = require('querystring');

const server = http.createServer((req, res) => {
    if(req.method === 'POST'){
        let postData = '';
        // 流stream的方式接收数据，'on'是请求的自带的监听
        // 监听'data'事件，开始接收数据时触发'data'事件
        req.on('data', chunk =>{
            postData += chunk.toString();
        })
        // 监听'end'事件，数据接收完成时触发'end'事件
        req.on('end', () => {
            console.log('postData', postData);
            res.end('数据接收完毕');
        })

        console.log('post data content type', req.headers['content-type']);
    }
});

server.listen(5000, () => {
    console.log('server running at port 5000');
})